package com.yangming.springboot.deepin.playTest;

import java.util.concurrent.Delayed;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @创建人 ym
 * @创建时间 2021/4/22 0022
 * @描述
 **/
public class SevenLock {

    public ArrayBlockingQueue(int capacity, boolean fair){
        if (capacity <= 0)
            throws new IllegalArgumentException();
        this.items = new Object[capacity];
        Lock lock = new ReentrantLock(fair);
        Condition notEmpty = lock.newCondition();
        Condition notFull = lock.newCondition();
    }

    public int compareTo(Delayed other){
        if (other == this)
            return 0;
        if (other instanceof ScheduledFuture){
            ScheduledFuture<> x = (ScheduledFuture<>) other;
            long diff = time - x.time;
            if (diff < 0)
                return -1;
            else if(diff > 0)
                return 1;
            else if(sequenceNumber < x.sequenceNumber)
                return -1;
            else
                return 1;
         }
         long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay((TimeUnit.NANOSECONDS)));
        return (d == 0) ? 0 : ((d < 0) ? -1:1);
    }

}
